package com.lzz.bottomencapsulation.manager;

import android.content.Context;

import com.lzz.bottomencapsulation.BuildConfig;
import com.lzz.bottomencapsulation.utils.LUtils;
import com.volcengine.mobsecBiz.metasec.listener.ITokenObserver;
import com.volcengine.mobsecBiz.metasec.ml.MSConfig;
import com.volcengine.mobsecBiz.metasec.ml.MSManagerUtils;

/**
 * @author lhx
 * @description: 连山管理类
 * @date : 2024/1/23 14:18
 */
public class RiskManager {

    // 风控数据
    static String appID = BuildConfig.LS_APP_ID;
    static String licenseStr =BuildConfig.LS_license ;
    static String channel = BuildConfig.LS_channel;

    private static RiskManager instance;

    private RiskManager() {
    }

    public static RiskManager getInstance() {
        if (instance == null) {
            synchronized (RiskManager.class) {
                if (instance == null) {
                    instance = new RiskManager();
                }
            }
        }
        return instance;
    }

    public void initRisk(Context context) {
        //初始化安全sdk
        initMetaSec(context);
        //初始化 token，调用此接口会开始采集并上报设备数据以及获取设备token，必须在初始化之后立即调用，避免缺失APP启动时的风险识别能力
        MSManagerUtils.initToken(appID);
    }

    void initMetaSec(Context context) {
        MSConfig.Builder builder = new MSConfig.Builder(appID, licenseStr, MSConfig.COLLECT_MODE_DEFAULT);
        //正常采集模式：MSConfig.COLLECT_MODE_DEFAULT
        //基础采集模式：MSConfig.COLLECT_MODE_ML_MINIMIZE
        MSConfig config = builder
                .setChannel(channel)
                .addDataObserver(new ITokenObserver() {
                    @Override
                    public void onTokenLoaded(String token) {
                        //此为回调方法，在SDK获取到设备token之后主动回调，可选，非必须使用回调
                        LUtils.d("============onRegisterSuccess==========token=====" + token);
//                        TokenUtil.getInstance().saveTokenLianShanRisk(token);
                    }
                })
                .build();
        MSManagerUtils.init(context, config);
    }


    //主动上报    like   登陆 login，提现 withdrawal，看广告activity
    public void reportRisk(String scene) {
        //        String scene = "test"; //场景名称，可任意填写。
        MSManagerUtils.get(appID).report(scene);
    }

    public static String login="login" ;

    public static String withdrawal="withdrawal" ;

    public static String activity="activity" ;
    public String getToken() {
        return MSManagerUtils.get(appID).getToken();
    }
}